// i.d(t, { H: () => o })
import Logger from "./Logger"
import browserUtil from "./browser.util"
import webvr from "webvr-polyfill"

const r = new Logger("vr-platform-select")

export default async () => {
  try {
    if ((await loadPoly(), !("getVRDisplays" in navigator))) return null
    const e = await navigator["getVRDisplays"]()
    if (e.length > 0 && e[0].capabilities.canPresent) return e[0]
  } catch (e) {
    r.warn("Getting VR display failed"), r.warn(e)
  }
  return null
}
const loadPoly = (() => {
  const e = browserUtil.isAndroid() && !("getVRDisplays" in navigator) && !browserUtil.isOculus()
  let t = !1
  return async () => {
    if (e && !t) {
      const n = new webvr()
      r.info(`Falling back to WebVR support, native:: ${n.hasNative}`, {
        webvrPolyfillNeeded: e,
        polyfill: n
      }),
        (t = !0)
    }
  }
})()
